package fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import fragment.detialfragment.RecordDetialFragment;
import qf.wlh.com.oneprisdent.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class RecordFragment extends Fragment {

    private View view ;
    private ViewPager viewPager;
    private List<Fragment> data;
    public RecordFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_record, container, false);
        viewPager = ((ViewPager) view.findViewById(R.id.record_fragment_viewPager));
        data = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            RecordDetialFragment recordDetialFragment = new RecordDetialFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("id",i);
            recordDetialFragment.setArguments(bundle);
            data.add(recordDetialFragment);
        }
        viewPager.setAdapter(new ViewPagerAdapter(getFragmentManager()));
        return view;
    }

    class ViewPagerAdapter extends FragmentPagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return data.get(position);
        }

        @Override
        public int getCount() {
            return data != null ? data.size() : 0;
        }
    }
}
